home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / slot_create.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  4.2 KB  |  124 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)slot_create.c    V1.6    3/13/95";
  3. #endif
  4. /*
  5. |    file name - slot_create.c
  6. |===================================================================
  7. |
  8. |       This example shows how to attach data to objects using
  9. |    the SLOT mechanism.  In this example, we show how to create
  10. |    SLOTs of the type OBJECT, STRING, and INT_ARRAY.  We define
  11. |    SLOTKEY objects for each of these types; create an empty
  12. |    view; attach the data for each of these types to the drawing
  13. |    in the view; and save the drawing to a file called "slot_temp.v"
  14. |
  15. |    Note that in this example we are adding the slots to the drawing
  16. |    object itself; you could just as easily add the slots to objects
  17. |    in the drawing.
  18. |
  19. |===================================================================
  20. */
  21. #include <windows.h>
  22.  
  23. #include "std.h"
  24. #include "dvstd.h"
  25. #include "dvtools.h"
  26. #include "VOstd.h"
  27. #include "Tfundecl.h"
  28. #include "VOfundecl.h"
  29.  
  30. #define ARRAY_SIZE 3
  31.  
  32. int iarray[ARRAY_SIZE] = {1, 2, 3};
  33. OBJECT object;
  34.  
  35. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  36.                      LPSTR lpCmdLine,  int nCmdShow  )
  37.   {
  38.   VIEW   view;
  39.   OBJECT drawing;
  40.   OBJECT iarraysk, namesk, objsk; 
  41.   OBJECT inobj;
  42.   int    *in_iarray;
  43.   char   *bufp;
  44.   int argc;
  45.   char **argv;
  46.   char mes_str[100];
  47.  
  48.   make_argv(&argc,&argv,GetCommandLine());
  49.   /* Initialize, creating an empty view */
  50.   TInit ((char *) NULL, (char *) NULL);  /* use DVPATH config var */
  51.   view = TviCreate ();
  52.   drawing = TviGetDrawing (view);
  53.  
  54.   /*--------------------------------------------------*/ 
  55.   /* Define the SLOTKEY objects.                      */ 
  56.   /* These define the data type and name of the slot. */ 
  57.   /*--------------------------------------------------*/ 
  58.   iarraysk = VOskDeclare ("V_INT_ARRAY", VOSK_INT_ARRAY_TYPE, ARRAY_SIZE);
  59.   namesk = VOskDeclare ("V_STRING", VOSK_STRING_TYPE);
  60.   objsk = VOskDeclare ("V_OBJECT", VOSK_OBJECT_TYPE);
  61.  
  62.   /* Create a rectangle to put in the object slot */
  63.   object = VOreCreate ( VOptCreate ( WORLD_COORDINATES, -100, -100, 
  64.                                     (OBJECT) NULL),
  65.                         VOptCreate ( WORLD_COORDINATES, 100, 100, 
  66.                                     (OBJECT) NULL),
  67.                         (ATTRIBUTES *) NULL);
  68.   VOobReference (object);
  69.  
  70.   /*--------------------------------------------------*/
  71.   /* Add the slots to the drawing object.              */
  72.   /*--------------------------------------------------*/
  73.   VOobSetSlot (drawing, iarraysk, (LONG *)iarray, (ULONG *) 0);
  74.   VOobSetSlot (drawing, namesk, (LONG *)"Hello World", (ULONG *) 0);
  75.   VOobSetSlot (drawing, objsk, (LONG *)&object, (ULONG *) 0);
  76.  
  77.   TviASCIISave (view, "slot_temp.v");
  78.   TviDestroy (view);
  79.  
  80.   /*--------------------------------------------------------------*/
  81.   /* Load the view that we just saved, and compare its slots to   */
  82.   /* the ones we just set                                         */
  83.   /*--------------------------------------------------------------*/
  84.   view = TviLoad ("slot_temp.v");
  85.   drawing = TviGetDrawing (view);
  86.  
  87.   /*---------------------------------------*/
  88.   /* Retrieve the contents of each slot.   */
  89.   /*---------------------------------------*/
  90.   VOobGetSlot (drawing, iarraysk, (LONG *)&in_iarray, (ULONG *) 0);
  91.   VOobGetSlot (drawing, namesk, (LONG *)&bufp, (ULONG *) 0);
  92.   VOobGetSlot (drawing, objsk, (LONG *)&inobj, (ULONG *) 0);
  93.  
  94.   /* Check the integer array slot */
  95.   if (iarray[0] == in_iarray[0] &&
  96.       iarray[1] == in_iarray[1] &&
  97.       iarray[2] == in_iarray[2])
  98.     sprintf ( mes_str,"INT ARRAY matched\n");
  99.   else
  100.     sprintf ( mes_str,"INT ARRAY did not match!!\n");
  101.  
  102.   /* Check the string slot */
  103.   if (0 == strcmp ("Hello World", bufp))
  104.     strcat( mes_str,"STRING matched\n");
  105.   else
  106.     strcat( mes_str,"STRING did not match!!\n");
  107.  
  108.   if (VOobType (object) == VOobType (inobj))
  109.     strcat( mes_str,"OBJECT matched\n");
  110.   else
  111.     strcat( mes_str,"OBJECT did not match!!\n");
  112.  
  113.   MessageBox (
  114.                GetFocus (),
  115.                mes_str,
  116.                "slot_create:",
  117.                MB_OK
  118.              );
  119.  
  120.   TviDestroy (view);
  121.   TTerminate ();
  122.   return (EXIT_OK);
  123. }
  124.